function $(el) {
    return document.querySelector(el);
}

function getTime(ts) {
    const date = new Date(ts);
    const y = date.getFullYear();
    const m = date.getMonth() + 1;
    const d = date.getDate();

    const h = date.getHours();
    const mi = date.getMinutes();
    const s = date.getSeconds();

    return [y, m, d].map(p).join('-') + ' ' + [h, mi, s].map(p).join(':');
}

function getDiffTime(ts) {
    const s = Math.round(ts / 1000);
    if (s < 60) return `${s}s`;
    const m = Math.round(s / 60);
    return `${m}m`;
}

const store = {
    set(key, data) {
        localStorage.setItem(key, JSON.stringify(data));
    },

    get(key) {
        const res = localStorage.getItem(key);
        if (!res) return;
        return JSON.parse(res);
    },

    remove(key) {
        localStorage.removeItem(key);
    },

    clear() {
        localStorage.clear();
    },
}